<?php

namespace app\common\model;

use think\Model;

class Banner extends Model
{
    protected $name = 'banner';

    /**
     * 根据ID查询单个轮播信息
     * @param $id   轮播ID
     * @return Banner|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getDetails($id){
        return self::where('id',$id)->find();
    }

    /**
     * @param $position 查询所属页面已开启的轮播
     * @param string $language  语言
     * @return Banner[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function position_list($position,$language = 'traditional'){
        $file = file_language('pic',$language);
        $data = self::where('position',$position)->where('status',1)->order('level desc,id desc')->field($file)->select();
        return $data;
    }

}